package cn.melon.mod.store.entity;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;

public class ShoppingCartInfo {
	private String student_number;
	private List<String> cartGoodsTable = new ArrayList<String>();
	

	
	public String getStudent_number() {
		return student_number;
	}



	public void setStudent_number(String student_number) {
		this.student_number = student_number;
	}



	public List<String> getCartGoodsTable() {
		return cartGoodsTable;
	}



	public void setCartGoodsTable(List<String> cartGoodsTable) {
		this.cartGoodsTable = cartGoodsTable;
	}

	public void add(String goodsId){
		cartGoodsTable.add(goodsId);
	}
	
	public void remove(String goodsId){
		cartGoodsTable.remove(goodsId);
	}
	
	public String get(int index){
		return cartGoodsTable.get(index);
	}
	
	public int length(){
		return cartGoodsTable.size();
	}

	/**
	 * @Title: setCartGoodsTable
	 *  用json格式的字符串来创建购物车列表
	 * @param jsonArr void
	 */
	public void setCartGoodsTable(String jsonArr){
		JSONArray jsonArray = null;
		try {
			jsonArray = new JSONArray(jsonArr);
			for(int i=0;i <jsonArray.length();i++){
				this.add(jsonArray.getString(i));
		}
		} catch (JSONException e1) {
			e1.printStackTrace();
		}
	}
	
	/**
	 * @Title: toJsonStr
	 *  转换为json格式的字符串
	 * @return String
	 */
	public String toJsonStr(){
		JSONArray jsonArray = new JSONArray();
		
		for(String string : cartGoodsTable){
			jsonArray.put(string);
		}
		return jsonArray.toString();
	}
}